//
//  VideoView.m
//  DD
//
//  Created by Burn on 2019/4/6.
//  Copyright © 2019 menksoft. All rights reserved.
//


//  视频点击通知  显示隐藏toolbar有关
#define kSECREENCLI_noti @"kSECREENCLI_noti"

/* 更换视频地址通知 比如
 CourseCatalogs *model = self.models[indexPath.item];
 NSDictionary *dict = @{@"VIDEO_URL" : model.AudioUrl};
 [[NSNotificationCenter defaultCenter]postNotificationName:kCHANGEVIDEOURL_noti object:nil userInfo:dict];
 */
#define kCHANGEVIDEOURL_noti @"kCHANGEVIDEOURL_noti"

#define SCREEN_WIDTH   [UIScreen mainScreen].bounds.size.width
#define SCREENH_HEIGHT [UIScreen mainScreen].bounds.size.height


//  iPhone_X
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IOS_11  ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.f)
#define IS_IPHONE_X (IS_IOS_11 && IS_IPHONE && (MIN([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) >= 375 && MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) >= 812))


#define FatherViewY ScreenHeight >= 812 ? 0 : 0


#import "VideoView.h"
#import "SPVideoPlayer.h"
#import "UINavigationController+FDFullscreenPopGesture.h"
#import "SPDownload.h"

//#import "MainViewController.h"
#import "ViewController.h"

#import "SPVideoPlayerView.h"
//#import "Header.h"
#import "SPVideoPopView.h"
//#import <Masonry/Masonry.h>
//#import "UIView+ShowMsg.h"
#import "PlaceholderView.h"

@interface VideoView ()<SPVideoPlayerDelegate,SPVideoPlayerControlViewDelegate,PlaceholderViewDelegate>

@property (strong, nonatomic)  UIView *playerFatherView;
@property(strong,nonatomic) UIButton *backBTN;
@property(strong,nonatomic) UIButton *playBTN;
@property(strong,nonatomic) UISlider *slider;
@property(strong,nonatomic) UIButton *fullBTN;
@property(strong,nonatomic) UIView *bottomView;
@property(strong,nonatomic) UIView *topView;
@property(strong,nonatomic) UILabel *currentTimeL;
@property(strong,nonatomic) UILabel *totalTimeL;
//  保存播放状态
@property(assign,nonatomic) SPVideoPlayerPlayState playStatu;

@property(strong,nonatomic) PlaceholderView *messageLabel;

/**自定义view*/
@property(strong,nonatomic) UIView *contentView;

/** 播放模型 */
@property (nonatomic, strong) SPVideoItem *videoItem;

/** 离开页面时候是否在播放 */
@property (nonatomic, assign) BOOL isPlaying;

@property (strong, nonatomic)  SPVideoPlayerView *playerView;

@property(copy,nonatomic)NSString *url;

/** 是否拖拽slider控制播放进度 */
@property (nonatomic, assign, getter=isDraggedBySlider) BOOL  draggedBySlider;

@property(assign,nonatomic) BOOL isShowing;
@property(assign,nonatomic) BOOL isFull;

//  从控制器中暂停
@property(assign,nonatomic) BOOL isControllerPause;

@end

@implementation VideoView

- (void)viewWillAppear:(BOOL)animated{
    // pop回来时候是否自动播放
    UINavigationController *nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    if (nav.viewControllers.count == 2 && self.playerView && self.isPlaying) {
        self.isPlaying = NO;
        self.playerView.playerPushedOrPresented = NO;
    }
}
- (void)viewWillDisappear:(BOOL)animated{
    // push出下一级页面时候暂停
    UINavigationController *nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    if (nav.viewControllers.count == 3 && self.playerView && !self.playerView.isPauseByUser)
    {
        self.isPlaying = YES;
        self.playerView.playerPushedOrPresented = YES;
    }

}

- (instancetype)initWithFrame:(CGRect)frame andURL:(NSString *)url{
    if (self = [super initWithFrame:frame]) {
        self.url = url;
        [self setupContentView];
        [self addTarget];
        
        // 开始播放，默认不开始播放
        [self.playerView startPlay];
        [self addTarget];
        [self addNotifications];
        
      
        
        //  监听屏幕点击
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(secreenClic) name:kSECREENCLI_noti object:nil];

        //  控制正在显示
        self.isShowing = YES;
        self.bottomView.hidden = YES;
        [self addSubview:self.playerFatherView];
        
    }
    return self;
}

#pragma mark - Lazy
- (UIView *)playerFatherView {
    
    if (!_playerFatherView) {
        _playerFatherView = [[UIView alloc] initWithFrame:self.bounds];
        _playerFatherView.backgroundColor = [UIColor blackColor];
    }
    return _playerFatherView;
}


- (SPVideoItem *)videoItem {
    if (!_videoItem) {
        _videoItem                  = [[SPVideoItem alloc] init];
        _videoItem.title            = @"视频标题";
        _videoItem.videoURL         = [NSURL URLWithString:self.url];
        _videoItem.placeholderImage = [UIImage imageNamed:@"SPVideoPlayer.bundle/qyplayer_aura2_background_normal_iphone_375x211_"];
        // playerView的父视图
        _videoItem.fatherView       = self.playerFatherView;
        _videoItem.shouldAutorotate = YES;
    }
    return _videoItem;
}

- (PlaceholderView *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [[PlaceholderView alloc]init];
        _messageLabel.hidden = YES;
        _messageLabel.delegate = self;
        _messageLabel.backgroundColor = [UIColor clearColor];
        _messageLabel.frame = CGRectMake(0, 0, self.bounds.size.width - 100, self.bounds.size.height - 100);
        _messageLabel.center = self.center;
    }
    return _messageLabel;
}


- (SPVideoPlayerView *)playerView {
    if (!_playerView) {
        _playerView = [[SPVideoPlayerView alloc] init];
        // 这一步非常重要，这一步相当于设置了控制层和视频模型,如果控制层传nil，则默认自带的的控制层
        [_playerView configureControlView:self.contentView videoItem:self.videoItem];
        // 如果有多个视频需要播放，如电视剧有很多集，则用这个方法
        //[_playerView configureControlView:nil videoItems:self.videoItems];
        _playerView.playerLayerGravity = SPPlayerLayerGravityResizeAspectFill;
        // 设置代理
        _playerView.delegate = self;
        _playerView.resumePlayFromLastStopPoint = NO;
        
    }
    return _playerView;
}


#pragma mark - SPVideoPlayerDelegate
- (void)sp_playerBackAction {
    
    if (self.slider.frame.size.width > [UIScreen mainScreen].bounds.size.height) {
        [self.playerView sp_controlViewFullScreenButtonClicked:nil];
        self.isFull = NO;
        self.isShowing = NO;
        self.fullBTN.selected = !self.fullBTN.selected;
        [self setNeedsLayout];
        [self layoutIfNeeded];
    }else{
        if ([self.delegate respondsToSelector:@selector(popClick)]) {
            [self.delegate popClick];
        }
    }
}



- (void)secreenClic{
//    self.playerView
    
     if (self.isShowing) {
            [UIView animateWithDuration:0.25 animations:^{
                self.bottomView.alpha = 0;
                //            self.topView.alpha = 0;
            }];
            self.isShowing = NO;
        }else{
            [UIView animateWithDuration:0.25 animations:^{
                self.bottomView.alpha = 1;
                //            self.topView.alpha = 1;
            }];
            self.isShowing = YES;
        }
}

- (void)sp_playerControlViewWillShow:(UIView *)controlView isFullscreen:(BOOL)fullscreen {
    //    self.backBtn.hidden = YES;
    [UIView animateWithDuration:0.25 animations:^{
        self.bottomView.alpha = 1;
    }];
}

- (void)sp_playerControlViewWillHidden:(UIView *)controlView isFullscreen:(BOOL)fullscreen {
    //    self.backBtn.hidden = fullscreen;
    [UIView animateWithDuration:0.25 animations:^{
        self.bottomView.alpha = 0;
    }];
}

#pragma mark - 自定义View
- (void)setupContentView{
    self.contentView = [[UIView alloc]initWithFrame:self.bounds];
    self.contentView.backgroundColor = [UIColor clearColor];
    
    [self.contentView addSubview:self.messageLabel];
    //  提示正在加载
    self.messageLabel.hidden = NO;
    [self.messageLabel holder];
    
    self.topView = [[UIView alloc]init];
    self.topView.frame = CGRectMake(0, 0, self.bounds.size.width, IS_IPHONE_X ? 60 : 45);
    [self.contentView addSubview:self.topView];

    self.backBTN = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.backBTN setImage:[UIImage imageNamed:@"play_back_half_20x20_"] forState:UIControlStateNormal];
    self.topView.userInteractionEnabled = YES;
    [self.contentView addSubview:self.backBTN];
    
    self.bottomView = [[UIView alloc]init];
    self.bottomView.frame = CGRectMake(0, self.bounds.size.height - 45, self.bounds.size.width , 45);
    [self.contentView addSubview:self.bottomView];
    
    self.playBTN = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.playBTN setImage:[UIImage imageNamed:@"player_full_play_iphone_30x30_"] forState:UIControlStateNormal];
    [self.playBTN setImage:[UIImage imageNamed:@"player_mini_pause_iphone_30x30_-1"] forState:UIControlStateSelected];
    [self.bottomView addSubview:self.playBTN];
    
    self.currentTimeL = [[UILabel alloc]init];
    self.currentTimeL.textColor = [UIColor whiteColor];
    self.currentTimeL.font = [UIFont systemFontOfSize:14];
    self.currentTimeL.text = @"00:00";
    [self.bottomView addSubview:self.currentTimeL];
    
    self.totalTimeL = [[UILabel alloc]init];
    self.totalTimeL.textColor = [UIColor whiteColor];
    self.totalTimeL.font = [UIFont systemFontOfSize:14];
    self.totalTimeL.text = @"00:00";
    [self.bottomView addSubview:self.totalTimeL];

    self.fullBTN = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.fullBTN setImage:[UIImage imageNamed:@"play_full_iphone_40x40_"] forState:UIControlStateNormal];
    [self.fullBTN setImage:[UIImage imageNamed:@"play_small_iphone_40x40_"] forState:UIControlStateSelected];
    [self.bottomView addSubview:self.fullBTN];
    
    self.slider = [[UISlider alloc]init];
   
    [self.bottomView addSubview:self.slider];
    
    [self.slider setThumbImage:[UIImage imageNamed:@"player_mini_slider_iphone_8x10_"] forState:UIControlStateNormal];
    self.backBTN.frame = CGRectMake(10, IS_IPHONE_X ? 45 : 40, 50, 50);
    self.playBTN.frame = CGRectMake(10, 0, 30, 30);
    self.fullBTN.frame = CGRectMake(self.bounds.size.width - 35, 0, 30, 30);
    self.slider.frame = CGRectMake(CGRectGetMaxX(self.playBTN.frame) + 5, 0, self.bounds.size.width - (CGRectGetMaxX(self.playBTN.frame) + 5) * 2, 30);
    
    self.topView.backgroundColor = [UIColor clearColor];
    self.bottomView.backgroundColor = [UIColor clearColor];
    
}

- (void)addTarget{
    [self.backBTN addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [self.fullBTN addTarget:self action:@selector(fullClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.playBTN addTarget:self action:@selector(playBTNClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.slider addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
    [self.slider addTarget:self action:@selector(slidertoucheDown:) forControlEvents: UIControlEventTouchUpInside | UIControlEventTouchCancel | UIControlEventTouchUpOutside];
    [self.slider addTarget:self action:@selector(sliderToucheBegin:) forControlEvents:UIControlEventTouchDown];
}
#pragma mark - 返回上面代理里执行
- (void)backClick{
    [self.playerView.delegate sp_playerBackAction];
}
#pragma mark - 全屏
- (void)fullClick:(UIButton *)btn{
    if (self.playStatu == SPVideoPlayerPlayStatePlaying || self.playStatu == SPVideoPlayerPlayStatePause) {
        self.isFull = !self.isFull;
        self.fullBTN.selected = !self.fullBTN.selected;
        [self.playerView sp_controlViewFullScreenButtonClicked:btn];
        [self setNeedsLayout];
        [self layoutIfNeeded];
    }
}
#pragma mark - 播放或暂停
- (void)playBTNClick:(UIButton *)btn{
    [self.playerView sp_controlViePlayOrPauseButtonClicked:btn];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    UIInterfaceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation;
    if (currentOrientation == UIDeviceOrientationPortrait) { // 竖屏
        self.fullBTN.frame = CGRectMake(self.bounds.size.width - 35, 0, 30, 30);
        self.topView.frame = CGRectMake(0, 0, self.bounds.size.width, IS_IPHONE_X ? 60 : 45);
        self.bottomView.frame = CGRectMake(0, self.bounds.size.height - 45, self.bounds.size.width , 45);
        self.currentTimeL.frame = CGRectMake(CGRectGetMaxX(self.playBTN.frame) , self.playBTN.frame.origin.y, 40, 35);
        self.totalTimeL.frame = CGRectMake(CGRectGetMinX(self.fullBTN.frame) - 40, self.fullBTN.frame.origin.y, 40, 35);
        self.slider.frame = CGRectMake(CGRectGetMaxX(self.currentTimeL.frame) + 5, 0, self.bounds.size.width - (CGRectGetMaxX(self.currentTimeL.frame) + 5) * 2, 30);
        self.messageLabel.frame = CGRectMake(0, 0, self.bounds.size.width - 100, self.bounds.size.height - 100);
        self.messageLabel.center = self.center;
        }else{
            
            self.fullBTN.frame = CGRectMake(SCREEN_WIDTH - 35, 0, 30, 30);
            self.topView.frame = CGRectMake(0, 0, SCREEN_WIDTH, IS_IPHONE_X ? 60 : 45);
            self.bottomView.frame = CGRectMake(0,SCREENH_HEIGHT - 45, SCREEN_WIDTH , 45);
            
            self.currentTimeL.frame = CGRectMake(CGRectGetMaxX(self.playBTN.frame) + 10, self.playBTN.frame.origin.y, 50, 35);
            self.totalTimeL.frame = CGRectMake(CGRectGetMinX(self.fullBTN.frame) - 50, self.fullBTN.frame.origin.y, 50, 35);
            self.slider.frame = CGRectMake(CGRectGetMaxX(self.currentTimeL.frame) + 5, 0, SCREEN_WIDTH - (CGRectGetMaxX(self.currentTimeL.frame) + 5) * 2, 30);
            
            self.messageLabel.frame = CGRectMake(50, 50, SCREEN_WIDTH - 100, SCREENH_HEIGHT - 100);
    }
}


- (void)addNotifications {
    // 监听播放状态的改变
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayerStateChanged:) name:SPVideoPlayerStateChangedNSNotification object:nil];
    // 监听播放进度的改变
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayerProgressValueChanged:) name:SPVideoPlayerProgressValueChangedNSNotification object:nil];
//    // 视频播放进度将要跳转
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayerWillJump:) name:SPVideoPlayerWillJumpNSNotification object:nil];
//    // 视频播放进度条转完毕
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayerDidJumped:) name:SPVideoPlayerDidJumpedNSNotification object:nil];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlyerBufferProgressValueChanged:) name:SPVideoPlayerBufferProgressValueChangedNSNotification object:nil];
//    // 监听视频截图
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cutVideoFinished:) name:SPVideoPlayerCutVideoFinishedNSNotification object:nil];
//    // 监听媒体网络加载状态
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadStatusDidChanged:) name:SPVideoPlayerLoadStatusDidChangedNotification object:nil];
//    // 监听videoPopView将要显示
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPopViewWillShow) name:SPVideoPopViewWillShowNSNotification object:nil];
//    // 监听videoPopView将要隐藏
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPopViewWillHide) name:SPVideoPopViewWillHideNSNotification object:nil];
//    // app退到后台
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterBackground) name:UIApplicationWillResignActiveNotification object:nil];
//    // app进入前台
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterPlayground) name:UIApplicationDidBecomeActiveNotification object:nil];
//    // 监听设备旋转
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(onDeviceOrientationChange)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];
}

- (void)onDeviceOrientationChange{
    if (self.isFull) {
        [self setNeedsLayout];
        [self layoutIfNeeded];
    }
}

#pragma mark - slider触摸结束
- (void)slidertoucheDown:(UISlider *)slider{
    self.draggedBySlider = NO;
    [self.playerView sp_controlViewSliderTouchEnded:slider];
}

#pragma mark - 开始触摸slider
- (void)sliderToucheBegin:(UISlider *)slider{
//    [self.playerView sp_controlViewSliderTouchBegan:slider];
    
}
#pragma mark - slider触摸中
- (void)sliderValueChange:(UISlider *)slider{
    self.draggedBySlider = YES;
    [self.playerView sp_controlViewSliderValueChanged:slider];
}

#pragma mark -  播放状态发生了改变
- (void)videoPlayerStateChanged:(NSNotification *)notification{
    SPVideoPlayerPlayState state = [notification.userInfo[@"playState"] integerValue];
    switch (state) {
        case SPVideoPlayerPlayStateReadyToPlay:
            //  提示即将播放
            self.messageLabel.hidden = NO;
            self.playBTN.selected = YES;
            [self.messageLabel wait];
            self.playStatu = SPVideoPlayerPlayStateReadyToPlay;
            break;
        case SPVideoPlayerPlayStatePlaying:         //  开始播放
            //  外界切换界面时调整
            if (self.isControllerPause) {[self.playerView pause]; self.playBTN.selected = YES;}
            
            self.bottomView.hidden = NO;
            self.messageLabel.hidden = YES;
            //  播放按钮更新状态
            self.playBTN.selected = NO;
            //  延迟隐藏 bottomView
            self.isShowing = YES;
            [self secreenClic];
            
            self.playStatu = SPVideoPlayerPlayStatePlaying;
            break;
        case SPVideoPlayerPlayStatePause:
            self.playBTN.selected = YES;
            //  显示bottomView
            self.isShowing = NO;
            [self secreenClic];
            self.playStatu = SPVideoPlayerPlayStatePause;
            break;
        case SPVideoPlayerPlayStateBuffering:
            self.messageLabel.hidden = NO;
            [self.messageLabel holder];
            self.playStatu = SPVideoPlayerPlayStateBuffering;
            break;
            
            case SPVideoPlayerPlayStateBufferSuccessed: //  缓存成功
            self.messageLabel.hidden = YES;
            self.playStatu = SPVideoPlayerPlayStateBufferSuccessed;
            break;
            case SPVideoPlayerPlayStateEndedPlay:       //  播放结束
            
            self.messageLabel.hidden = NO;
            [self.messageLabel replay];
            self.playBTN.selected = NO;
            self.playStatu = SPVideoPlayerPlayStateEndedPlay;
            //  隐藏bottomView
            self.isShowing = YES;
            [self secreenClic];
            
        default:
            break;
    }
}
#pragma mark - 播放进度发生了改变
- (void)videoPlayerProgressValueChanged:(NSNotification *)notification{
    // 当前时间
    CGFloat currentTime = [notification.userInfo[@"currentTime"] floatValue];
    // 总时间
    CGFloat totalTime = [notification.userInfo[@"totalTime"] floatValue];
    // 当前时间与总时间之比
    CGFloat value = [notification.userInfo[@"value"] floatValue];
    // 进度状态，分为自然状态、快进状态、快退状态
//    SPVideoPlayerPlayProgressState playProgressState = [notification.userInfo[@"playProgressState"] integerValue];
    // 是否要求显示快进快退时的预览图
//    BOOL requirePreviewView = [notification.userInfo[@"requirePreviewView"] integerValue];
    
    // 秒数转时分秒
    double current_hours = floorf(currentTime/(60.0*60.0));
    double current_minutes = floorf(fmod(currentTime, 60.0*60.0)/60.0);
    double current_seconds = fmod(currentTime, 60.0);
    
    double total_hours = floorf(totalTime/(60.0*60.0));
    double total_minutes = floorf(fmod(totalTime, 60.0*60.0)/60.0);;
    double total_seconds = fmod(totalTime, 60.0);
    
    NSString *currentTimeString;
    //  更新slider的Value
    if (!self.draggedBySlider) {
        self.slider.value = value;
    }
    
    if (current_hours > 0) {
        if (current_hours < 1) {
            current_hours = 0.00;
        }
        currentTimeString = [NSString stringWithFormat:@"%02.0f:%02.0f:%02.0f", current_hours, current_minutes, current_seconds];
    } else {
        
        if (current_minutes < 1) {
            current_minutes = 0.00;
        }
        currentTimeString = [NSString stringWithFormat:@"%02.0f:%02.0f", current_minutes, current_seconds];
    }
    self.currentTimeL.text = currentTimeString;
    
    NSString *totalTimeString;
    if (total_hours > 0) {
        if (total_hours < 1) {
            total_hours = 0.00;
        }
        totalTimeString = [NSString stringWithFormat:@"%02.0f:%02.0f:%02.0f", total_hours, total_minutes, total_seconds];
    } else {
        if (total_minutes < 1) {
            total_minutes = 0.00;
        }
        totalTimeString = [NSString stringWithFormat:@"%02.0f:%02.0f", total_minutes, total_seconds];
    }
    self.totalTimeL.text = totalTimeString;
}
#pragma mark - 监听媒体网络加载状态
- (void)loadStatusDidChanged:(NSNotification *)noti{
    SPVideoPlayerLoadStatus status = [noti.userInfo[@"loadStatus"] integerValue];
    BOOL bufferEmpty = [noti.userInfo[@"bufferEmpty"] boolValue];
    
    switch (status) {
        case SPVideoPlayerLoadStatusNotReachable:
            NSLog(@"无网络");
            if (bufferEmpty) { // 无网络且缓存为空
                self.messageLabel.hidden = NO;
                [self.messageLabel checkInternet];
                
            }
            break;
        case SPVideoPlayerLoadStatusReachableViaWWAN:{
            self.messageLabel.hidden = NO;
            [self.messageLabel phoneData];
        }
            break;
        case SPVideoPlayerLoadStatusReachableViaWiFi:{
            
//            self.messageLabel.hidden = YES;
        }
            NSLog(@"WiFi");
            break;
        case SPVideoPlayerLoadStatusUnknown | SPVideoPlayerLoadStatusAbnormal:
            [self.messageLabel phoneData];
            NSLog(@"未知 || 网络异常");
            break;
            
        default:
            break;
    }
    
}
#pragma mark - PlaceholderViewDelegate
//  重播
- (void)replayClick{
    [self.playerView sp_controlViewRepeatButtonClicked:nil];
}
//  继续
- (void)resumeClick{
    [self.playerView sp_controlViePlayOrPauseButtonClicked:nil];
}
//  重试
- (void)tryAgainClick{
    [self.playerView sp_controlViewRepeatButtonClicked:nil];
}



#pragma mark - Public
- (void)resume{
    self.isControllerPause = NO;
}

- (void)pause{
    [self.playerView pause];
    self.playBTN.selected = YES;
    self.isControllerPause = YES;
}

- (void)changeUrl:(NSString *)url{
    self.url = @"http://203.57.230.154:8089/Document/resource/8501705994ab4f62aec1e5ea267eed93/Audios/1.MP4";
    [self.playerView stop];
    self.videoItem = nil;
    self.playerView = nil;
    
    [self.playerView startPlay];
    self.messageLabel.hidden = NO;
    [self.messageLabel holder];
}
/*- (UIView *)playerFatherView {
 
 if (!_playerFatherView) {
 _playerFatherView = [[UIView alloc] initWithFrame:self.bounds];
 _playerFatherView.backgroundColor = [UIColor blackColor];
 }
 return _playerFatherView;
 }
 
 
 - (SPVideoItem *)videoItem {
 if (!_videoItem) {
 _videoItem                  = [[SPVideoItem alloc] init];
 _videoItem.title            = @"视频标题";
 _videoItem.videoURL         = [NSURL URLWithString:self.url];
 _videoItem.placeholderImage = [UIImage imageNamed:@"SPVideoPlayer.bundle/qyplayer_aura2_background_normal_iphone_375x211_"];
 // playerView的父视图
 _videoItem.fatherView       = self.playerFatherView;
 _videoItem.shouldAutorotate = YES;
 }
 return _videoItem;
 }*/


- (void)dealloc
{
    [self.playerView stop];
    self.playerView = nil;
    NSLog(@"VideoView - dealloc");
}

@end
